while condition : statement --------- --------- next statements
i=1 while i<=10: print(i) i=i+1
1 2 3 4 5 6 7 8 9 10
i=1 While i<=10: print(i,end=' ') i=i+1
1 2 3 4 5 6 7 8 9 10
i=10 while i>=1: print (i,end=' ') i=i-1
10 9 8 7 6 5 4 3 2 1
i=1 while i<=100: print(i,end=' ') i=i+2
i=2 while i<=100: print(i,end=' ') i=i+2
i=1 while i<=100: if i % 2==0 : print(i,end=' ') i=i+2
a=int(input("Enter a Number ")) i=1 while i<=a: print(i,end=' ') i=i+1
Enter a Number: 12 1 2 3 4 5 6 7 8 9 10 11 12
a=int(input("Enter a Number ")) i=1 while i<=a: print(i,end=' ') i=i+2
Enter a Number: 25 1 3 5 7 9 11 13 15 17 19 21 23 25
a=int(input("Enter a Number ")) i=2 while i<=a: print(i,end=' ') i=i+2
Enter a Number: 24 2 4 6 8 10 12 14 16 18 20 22 24
a,b=input("Enter 2 Numbers ").split() a,b=int(a),int(b) while a<=b: print(a,end=' ') a=a+1
Enter 2 Number: 12 24 12 13 14 15 16 17 18 19 20 21 22 23 24
a,b=input("Enter 2 Numbers ").split() a,b=int(a),int(b) while a>=b : print(a,end=' ') a=a-1
Enter 2 Number: 50 35 50 49 48 47 46 45 44 43 42 41 30 39 38 37 36 35
a,b=input("Enter 2 Numbers ").split() a,b=int(a),int(b) if a<b : while a<=b: print(a,end=' ') a=a+1 else: while a>=b : print(a,end=' ') a=a-1
Enter 2 Number: 50 35 50 49 48 47 46 45 44 43 42 41 30 39 38 37 36 35 Enter 2 Number: 12 24 12 13 14 15 16 17 18 19 20 21 22 23 24
i=1 while i<=10: print("Amravati") i=i+1
Amravati Amravati Amravati Amravati Amravati Amravati Amravati Amravati Amravati
i=1 s=0 while i<=10 : a=int(input("Enter a Number")) s=s+a i=i+1 print("Sum is ",s)
Enter a Number 5 Enter a Number 15 Enter a Number 5 Enter a Number 5 Enter a Number 10 Enter a Number 5 Enter a Number 5 Enter a Number 25 Enter a Number 5 Enter a Number 5 Sum is 85
i=1 s=0 while i<=10: a=int(input("Enter a Number")) if a%2==0: s=s+a i=i+1 print("Sum of even numbers is ",s)
Enter a Number 12 Enter a Number 15 Enter a Number 2 Enter a Number 5 Enter a Number 10 Enter a Number 6 Enter a Number 5 Enter a Number 25 Enter a Number 8 Enter a Number 5 Sum of even numbers is 38
i=1 s1,s2=0,0 while i<=10 : a=int(input("Enter a Number")) if a%2==0 : s1=s1+a else: s2=s2+a i=i+1 print("Sum of even nos is ",s1) print("Sum of odd nos is ",s2)
Enter a Number 5 Enter a Number 15 Enter a Number 5 Enter a Number 5 Enter a Number 10 Enter a Number 5 Enter a Number 5 Enter a Number 20 Enter a Number 5 Enter a Number 5 Sum of even nos is 30 Sum of odd nos is 55
while condition : statements ---------- else: statements ----------
n=int(input("Enter a number")) i=2 while i<n: if n%i==0: print("Number is not prime") break i=i+1 else: print("Number is prime")
Enter a Number: 9 Number is not prime Enter a Number: Number is prime